import { verify } from '@/utils/request';
import { createRouter, createWebHashHistory } from 'vue-router';
import Home from 'views/Home/Home.vue';
import type { AnyObj } from '@/utils/type';

interface BreadcrumbNameParamsType {
	params?: AnyObj;
}

const router = createRouter({
	history: createWebHashHistory(),
	routes: [
		{
			path: '/',
			component: Home,
			children: []
		},
		{
			path: '/home',
			name: 'Home',
			component: Home,
			children: [
				{
					path: '/outletList',
					name: 'OutletList',
					component: () => import('views/OutletList/OutletList.vue'),
					meta: {
						breadcrumbName: '网点列表',
					}
				},
				{
					path: '/saveOutlet/:id',
					name: 'SaveOutlet',
					component: () => import('views/SaveOutlet/SaveOutlet.vue'),
					meta: {
						breadcrumbName: '网点管理',
					}
				},
				{
					path: '/userList',
					name: 'UserList',
					component: () => import('views/UserList/UserList.vue'),
					meta: {
						breadcrumbName: '下单用户列表',
					}
				},
				{
					path: '/userOrderList/:userId',
					name: 'UserOrderList',
					component: () => import('views/UserOrderList/UserOrderList.vue'),
					meta: {
						breadcrumbName: '下单用户订单列表',
					}
				}
			]
		},
		{
			path: '/login',
			name: 'Login',
			component: () => import('views/Login/Login.vue')
		}
	]
})

router.afterEach(async (to, from) => {
	if (to.fullPath != '/') {
		// console.log('to: ', to);
		// console.log('from: ', from)
		// console.log(['/login', '/signUp', '/forgotPassword'].includes(to.path));
		if (['/login'].includes(to.path) === false) {
			verify();
		}
	}
});

export default router;